package com.shinetech.service;

import com.shinetech.entity.BaseEntity;
import com.shinetech.repository.BaseRepository;
import com.shinetech.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.Repository;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by joy on 2017/6/30.
 */
public class BaseService<Entity extends BaseEntity> {

    @Autowired
    public BaseRepository<Entity> repository;

    public void save(Entity entity){
        repository.save(entity);
    }

    public Entity getOne(long id){
        Entity entity = repository.getOne(id);
        return   entity;
    }

    public void delete(long id){
        repository.delete(id);
    }

    public void updateById(Entity entity) {
        repository.saveAndFlush(entity);
    }

    public void deleteById(long id) {
        repository.delete(id);
    }

    public void deleteByIds(List<Long> ids){
        for(Long id: ids){
            repository.delete(id);
        }
    }


    public List<Entity> selectListAll() {
        return repository.findAll();
    }
}
